package DiskInfo;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileSystemUtils;
import org.apache.commons.io.FileUtils;

public class FreeSpace {
	public void getDiskFree(){
		File file = new File("C:");  
         long totalSpace = file.getTotalSpace();  
        long freeSpace = file.getFreeSpace();  
        long usedSpace = totalSpace - freeSpace;  
        System.out.println("总空间大小 : " + totalSpace / 1024 / 1024 / 1024 + "G");  
        System.out.println("剩余空间大小 : " + freeSpace / 1024 / 1024 / 1024 + "G");  
	}
	
	public static void main(String[] args) {
		try {

			// Set a string with the path
			String path = "C:";

			// Get free space in KB
			long freeSpaceInKB = FileSystemUtils.freeSpaceKb(path);

			// Calculate free space in GB
			long freeSpaceInGB = freeSpaceInKB / FileUtils.ONE_MB;

			// Print the result
			System.out.println("Free space of " + path + " drive = "
					+ freeSpaceInGB + " GB");

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
